package com.cdy.sample_client2.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.cdy.sample_client2.service.FeignService;

@RestController
@RefreshScope
public class HelloController {
    
	private final DiscoveryClient discoveryClient;

	@Autowired
	public HelloController(DiscoveryClient discoveryClient) {
		this.discoveryClient = discoveryClient;
	}
	 
   @Autowired
   private RestTemplate restTemplate;
   @Autowired
   private FeignService feignService;

   @GetMapping("/test")
   public String test(){
       return feignService.test();
   }
    
  /*  @Value("${client.port}")
    private String port;
    
    @Value("${client.service.id}")*/
    private String client = "producer";
    
    @RequestMapping("/hello")
    public String hello() {
        String body = restTemplate.getForEntity("http://" + client + "/world", String.class).getBody();
        return body;
    }
    
/*    @RequestMapping("/world")
    public String world() {
        return client + ":" + port;
    }*/
    
    	@Autowired
    	private LoadBalancerClient loadBalancer;
     
    	
    	@RequestMapping("/discovery")
    	public Object discovery() {
    		System.out.println(loadBalancer.choose("spring-cloud-zookeeper-client-test"));
    		return "discovery";
    	}

 
    
}
